package cn.lysj.framework.api.controller;

import cn.lysj.framework.api.base.ApiContent;
import cn.lysj.framework.common.annotation.CurrentUser;
import cn.lysj.framework.common.domain.User;
import cn.lysj.framework.common.utils.pagination.PageVo;
import cn.lysj.framework.common.utils.web.ParamUtil;
import cn.lysj.framework.common.utils.web.Resp;
import cn.lysj.framework.customer.domain.Customer;
import cn.lysj.framework.customer.domain.CustomerInfo;
import cn.lysj.framework.customer.domain.CustomerVip;
import cn.lysj.framework.foodv2.domain.Food;
import cn.lysj.framework.foodv2.dto.FoodListDto;
import cn.lysj.framework.order.domain.FoodOrder;
import cn.lysj.framework.order.domain.FoodOrderInfo;
import cn.lysj.framework.order.service.FoodOrderService;
import cn.lysj.framework.pirpraph.domain.FoodReport;
import cn.lysj.framework.store.domain.Store;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Date;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;


/**
 * @ Author ：drj.
 * @ Date  ：Created in 9:31 2018/11/19
 * @ Description: 商户后台人员业务端
 **/
@RestController
@RequestMapping("/app/store")
public class AppUserManageController extends ApiContent {


    /**
     * @author zwj
     * @date 2018-11-23 10:05
     * @@Description:获取用户信息
     */
    @GetMapping("/getUserMsg")
    public Resp getUserMsg(@CurrentUser User user) {
        User returnUser = user;
        returnUser.setPassword("");
        return new Resp(returnUser);
    }


    /**
     * @author drj
     * @date 2018/11/19 9:48
     * @Description:显示所有菜品
     */
    @GetMapping("/show_all_food")
    public Resp showAllFood(@CurrentUser User user, FoodListDto foodListDto, PageVo pageVo) {
        return foodService.foodList(user, foodListDto, pageVo);
    }


    /**
     * @author drj
     * @date 2018/11/15 10:33
     * @Description:菜品售罄
     */
    @PostMapping("/food_sold_out")
    public Resp foodSoldOut(String foodId) {
        if (ParamUtil.isBlank(foodId)) {
            return new Resp(Resp.PARAM_ERROR, "请选择菜品");
        }
        Food food = foodService.getRepository().findOne(foodId);
        if (null == food) {
            return new Resp(Resp.PARAM_ERROR, "请联系管理员");
        }
        if (-1 == food.getOnSale()) {
            food.setOnSale(1); //设置菜品状态为在售
        } else {
            food.setOnSale(-1); //设置菜品状态为售罄
        }
        foodService.getRepository().save(food);
        return new Resp("操作成功");
    }


    /**
     * @author drj
     * @date 2018/11/19 10:02
     * @Description:上菜完成
     */
    @PostMapping("/food_close")
    public Resp foodClose(String foodOrderId) {
        return foodOrderService.foodClose(foodOrderId);
    }

    @PostMapping("/affirm_money_to_order")
    public Resp affirmMoneyToOrder(String orderId) {
        return foodOrderService.affirmMoneyToOrder(orderId);
    }


    /**
     * @author drj
     * @date 2018/11/19 10:24
     * @Description:显示商户订单
     */
    @PostMapping("/show_store_order")
    public Resp showStoreOrder(@CurrentUser User user, Integer staus, PageVo pageVo) {
        return foodOrderService.showStoreOrders(user.getId(), staus, pageVo);
    }

    /**
     * @param user
     * @return cn.lysj.framework.common.utils.web.Resp
     * @author ZhangWenJian
     * @date 2019/1/7 14:39
     * @title showStoreOrder
     * @description 显示需要打印订单
     */
    @PostMapping("/show_print_order")
    public Resp showPrintOrder(@CurrentUser User user) {
        return foodOrderService.showPrintOrder(user.getStoreId());
    }

    /**
     * @param user
     * @param showTime
     * @return cn.lysj.framework.common.utils.web.Resp
     * @author ZhangWenJian
     * @date 2019/2/15 14:22
     * @title new_food_order
     * @description 轮询订单
     */
    @PostMapping("/new_food_order")
    public Resp new_food_order(@CurrentUser User user, String showTime) {
        Long test = new Long(showTime);
        return foodOrderService.newFoodOrder(user.getStoreId(), test);
    }

}
